package com.lz.football.module.rankinglist
{
	import com.common.utils.Reflection;
	import com.liangzhong.constants.ClubConst;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.FriendEvent;
	import com.liangzhong.model.friend.vo.FriendInfoVo;
	import com.liangzhong.model.rankinglist.RankingListVo;
	import com.lz.football.module.base.IComponent;
	
	import common.BaseView.IItemMouseEvent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class RankingItem extends Sprite implements IComponent, IItemMouseEvent
	{
		private var _skin:MovieClip;
		/**
		 *排名状态 
		 */
		private var status:MovieClip;
		/**
		 *排名  
		 */
		private var sort:TextField;
		/**
		 *玩家名称  
		 */
		private var playerName:TextField;
		/**
		 *国家图标  
		 */
		private var gIcon:MovieClip;
		
		/**
		 *国家 
		 */
		private var country:TextField;
		/**
		 *值  
		 */
		private var value:TextField;
		private var frame:MovieClip;
		/**
		 * 排名颜色
		 */
		private var rankBg:MovieClip;
		/**
		 *ID 
		 */
		private var _id:int
		private var _vo:RankingListVo;
		public function RankingItem()
		{
			super();
		}
		
		public function initUI(view:Object=null):void
		{
			_skin= Reflection.createInstance("com.lz.modul.rankingList.rankItem");
			this.addChild(_skin);
			
			status = _skin.status;
			status.gotoAndStop(3);	
			status.visible = false;
			sort = _skin.sort;
			frame = _skin.frame;
			frame.visible = false;
			playerName = _skin.playerName;
			gIcon = _skin.gIcon
			country = _skin.country;
			value = _skin.value;
			rankBg = _skin.rankBg;
			rankBg.gotoAndStop(1);
			addEvtListener();
		}
		
		/**
		 *设置数据 
		 * 
		 */
		public function setdate($vo:RankingListVo):void
		{
			_id = $vo.clubid;
			_vo = $vo;
			sort.text = "" + $vo.sort ;
			playerName.text = $vo.uname + "";
			gIcon.gotoAndStop($vo.country);
			country.text = ClubConst.countryToString($vo.country);
			value.text = $vo.value + "";
			rankBg.gotoAndStop($vo.sort);
//			if($vo.status <=0)
//			{
//				status.gotoAndStop(3);
//			}else
//			{
//				status.gotoAndStop($vo.status);
//			}
				
//			rankBg.gotoAndStop(0);
			switch($vo.sort)
			{
				case 1:
					setTextColor(0xFF0000);
					break;
				case 2:
					setTextColor(0xF4CCD0);
					break;
				case 3:
					setTextColor(0xFFEACA);
					break;
				case 4:
					setTextColor(0xAAAAFF);
					break;
				case 5:
					setTextColor(0x8ED2FF);
					break;
				case 6:
					setTextColor(0xB9FFB9);
					break;
				case 7:
					setTextColor(0x939393);
					break;
				default:
					setTextColor(0x939393);
					
			}
		}
			
		/**
		 *设置国家排名  
		 * 
		 */
		public function setNationSort():void
		{
			switch(_vo.sort)
			{
				case 1:
					sort.text = "国王";
					break;
				case 2:
				case 3:
				case 4:
					sort.text = "大将";
					break;
					
			}
		}
			
		private function setTextColor($value:uint):void
		{
			sort.textColor = $value
			playerName.textColor = $value;
			country.textColor = $value
			value.textColor = $value
		}
		
		
		
		public function addEvtListener():void
		{
			this.addEventListener(MouseEvent.CLICK,onMouseClick);
			this.addEventListener(MouseEvent.ROLL_OUT,onMouseRollOut);
			this.addEventListener(MouseEvent.ROLL_OVER,onMouseRollOver);
		}
		
		public function removeEvtListener():void
		{
			this.removeEventListener(MouseEvent.CLICK,onMouseClick);
			this.removeEventListener(MouseEvent.ROLL_OUT,onMouseRollOut);
			this.removeEventListener(MouseEvent.ROLL_OVER,onMouseRollOver);
		}
		
		public function destroyView():void
		{
			removeEvtListener();
			if(this.parent)
				this.parent.removeChild(this);
		}
		
		public function onMouseRollOut(event:MouseEvent):void
		{
			frame.visible = false;
		}
		
		public function onMouseRollOver(event:MouseEvent):void
		{
			frame.visible = true;
		}
		
		public function onMouseClick(event:MouseEvent):void
		{
			var f:FriendInfoVo = new FriendInfoVo();
			f.friendid = _id;
			//			listBg.removeEventListener(MouseEvent.CLICK,onMouseClick);
			AppEventDispatcher.getInstance().dispatchEvent(new FriendEvent(FriendEvent.LOOK_UP_FRIEND,{vo:f}));
		}
		
		public function get tips():Object
		{
			return null;
		}
		
		public function set tips(value:Object):void
		{
		}
	}
}